Skip to content

Include metadata scopes in WWW-Authenticate challenge - #2196

Open
sdelamo wants to merge 2 commits into
5.1.xfrom
paperclip/mng-287-www-authenticate-scopes
Open

Include metadata scopes in WWW-Authenticate challenge#2196
sdelamo wants to merge 2 commits into
5.1.xfrom
paperclip/mng-287-www-authenticate-scopes

Conversation

@sdelamo

@sdelamo sdelamo commented May 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Source the Bearer scope challenge parameter from ProtectedResourceMetadataProvider for the current request or path-specific protected-resource metadata.
  • Preserve the existing resource_metadata challenge behavior and omit scope when metadata scopes are null, empty, or blank-only.
  • Update protected-resource metadata and WWW-Authenticate docs for the provider-backed behavior.

Release Target

Verification

  • git diff --check -- security-oauth2/src/main/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProvider.java security-oauth2/src/test/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProviderTest.java src/main/docs/guide/oauth/oauth-endpoints/protectedResourceMetadata.adoc src/main/docs/guide/rejection/wwwAuthenticate.adoc
  • ./gradlew :micronaut-security-oauth2:test --tests io.micronaut.security.oauth2.metadata.ResourceMetadataWwwAuthenticateChallengeProviderTest --no-daemon --no-build-cache --rerun-tasks (7 tests, 7 successes)

PR Assets

  • None. This change updates Java source, tests, and AsciiDoc source; no rendered images, PDFs, logs, archives, or generated assets changed.

Closes #2079


✨ This message was AI-generated using gpt-5

Copilot AI review requested due to automatic review settings May 22, 2026 10:23
@sdelamo sdelamo added the type: improvement A minor improvement to an existing feature label May 22, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the OAuth2 protected-resource metadata integration by adding an optional scope parameter to the WWW-Authenticate: Bearer challenge, sourced from ProtectedResourceMetadataProvider for the current request (including path-specific metadata). It keeps the existing resource_metadata challenge parameter behavior and documents the new scope-emission behavior.

Changes:

  • Add scope to the Bearer WWW-Authenticate challenge when ProtectedResourceMetadata.scopesSupported() is non-empty after trimming.
  • Extend test coverage to validate scope emission and omission for null/empty/blank-only scope lists.
  • Update the OAuth protected-resource metadata and WWW-Authenticate documentation to describe provider-backed scope behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
security-oauth2/src/main/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProvider.java Adds provider-derived scope parameter emission while preserving existing resource_metadata behavior.
security-oauth2/src/test/java/io/micronaut/security/oauth2/metadata/ResourceMetadataWwwAuthenticateChallengeProviderTest.java Adds tests for scope inclusion from path-specific metadata and omission when scopes are null/empty/blank-only.
src/main/docs/guide/oauth/oauth-endpoints/protectedResourceMetadata.adoc Documents that the same metadata provider also drives Bearer challenge scopes.
src/main/docs/guide/rejection/wwwAuthenticate.adoc Documents when scope will be included in the Bearer WWW-Authenticate challenge.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: improvement A minor improvement to an existing feature

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Improve www-authenticate default scopes

2 participants